﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace iTeamyou.LTS.Core.Migrations
{
    public partial class Update100902 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "RemainingDays",
                table: "BatchLicenses");

            migrationBuilder.RenameColumn(
                name: "ValidDate",
                table: "BatchLicenses",
                newName: "ValidToDate");

            migrationBuilder.AddColumn<string>(
                name: "LId",
                table: "BatchLicenses",
                type: "longtext",
                nullable: false)
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AddColumn<DateTime>(
                name: "ValidFromDate",
                table: "BatchLicenses",
                type: "datetime",
                nullable: true);

            migrationBuilder.AlterColumn<int>(
                name: "ValidDate",
                table: "Batches",
                type: "int",
                nullable: true,
                oldClrType: typeof(DateTime),
                oldType: "datetime",
                oldNullable: true);

            migrationBuilder.UpdateData(
                table: "Batches",
                keyColumn: "SupplierId",
                keyValue: null,
                column: "SupplierId",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "SupplierId",
                table: "Batches",
                type: "varchar(95)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.UpdateData(
                table: "Batches",
                keyColumn: "ProductId",
                keyValue: null,
                column: "ProductId",
                value: "");

            migrationBuilder.AlterColumn<string>(
                name: "ProductId",
                table: "Batches",
                type: "varchar(95)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "longtext",
                oldNullable: true)
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_Batches_ProductId",
                table: "Batches",
                column: "ProductId");

            migrationBuilder.CreateIndex(
                name: "IX_Batches_SupplierId",
                table: "Batches",
                column: "SupplierId");

            migrationBuilder.AddForeignKey(
                name: "FK_Batches_Products_ProductId",
                table: "Batches",
                column: "ProductId",
                principalTable: "Products",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_Batches_Suppliers_SupplierId",
                table: "Batches",
                column: "SupplierId",
                principalTable: "Suppliers",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Batches_Products_ProductId",
                table: "Batches");

            migrationBuilder.DropForeignKey(
                name: "FK_Batches_Suppliers_SupplierId",
                table: "Batches");

            migrationBuilder.DropIndex(
                name: "IX_Batches_ProductId",
                table: "Batches");

            migrationBuilder.DropIndex(
                name: "IX_Batches_SupplierId",
                table: "Batches");

            migrationBuilder.DropColumn(
                name: "LId",
                table: "BatchLicenses");

            migrationBuilder.DropColumn(
                name: "ValidFromDate",
                table: "BatchLicenses");

            migrationBuilder.RenameColumn(
                name: "ValidToDate",
                table: "BatchLicenses",
                newName: "ValidDate");

            migrationBuilder.AddColumn<int>(
                name: "RemainingDays",
                table: "BatchLicenses",
                type: "int",
                nullable: true);

            migrationBuilder.AlterColumn<DateTime>(
                name: "ValidDate",
                table: "Batches",
                type: "datetime",
                nullable: true,
                oldClrType: typeof(int),
                oldType: "int",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "SupplierId",
                table: "Batches",
                type: "longtext",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "varchar(95)")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.AlterColumn<string>(
                name: "ProductId",
                table: "Batches",
                type: "longtext",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "varchar(95)")
                .Annotation("MySql:CharSet", "utf8mb4")
                .OldAnnotation("MySql:CharSet", "utf8mb4");
        }
    }
}
